package com.itheima.health.jobs;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.service.OrderService;
import com.itheima.health.service.OrderSettingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @Description:清理历史数据
 * @Date: 2020-8-23 15:23
 * @Auther: 王肖
 */
@Slf4j
@Controller
public class ClearOrderSetting {

    @Reference
    private OrderSettingService orderSettingService;

    @Reference
    private OrderService orderService;



    public void clearOrderSettingJob(){
        log.info("[开始清理]");
        //自动清理过期的历史数据,清除今天之前的预约信息
        Calendar calendar = Calendar.getInstance();
        //获取今天的时间
        Date date = calendar.getTime();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String currentTime = simpleDateFormat.format(date);
        //查询数据库，删除小于当前时间的数据,ordersetting表和order表
        orderSettingService.deleteByDate(currentTime);
        //查询order，删除过期数据
        orderService.deleteByDate(currentTime);
        log.info("[清理完成]");
    }
}
